<?php
    namespace yaliSDK\utils;
    use yaliSDK\message\BaseMessage;
    use yaliSDK\message\Code;
    use yaliSDK\message\ExceptionFactory;

    class Validate {
        static public function length($value, $name = '', $limit = 50): BaseMessage {
            if (!empty($value)) {
                if (gettype($value) === 'string') {
                    if (strlen($value) < $limit) {
                        if (strpos($value,'|')>-1) {
                            return new BaseMessage(Code::$ERROR, $name.'输入有误');
                        } else {
                            return ExceptionFactory::getInstance()->getMessage(Code::$SUCCESS);
                        }

                    } else {
                        return new BaseMessage(Code::$ERROR, $name.'长度过长');
                    }

                } else {
                    return new BaseMessage(Code::$ERROR, $name.'类型错误');
                }

            } else {
                return new BaseMessage(Code::$ERROR, $name.'空');
            }

        }
    }
